package com.qingzhuge.member.controller;

import com.qingzhuge.common.validator.ValidatorUtil;
import com.qingzhuge.controller.base.AbstractController;
import com.qingzhuge.core.annotation.security.Anonymous;
import com.qingzhuge.dto.response.BaseResponseDto;
import com.qingzhuge.dto.response.ResponseBodyDto;
import com.qingzhuge.member.dto.UserRegisterRequestDto;
import com.qingzhuge.member.service.ISysMemberService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author : zero.xiao
 * @description :
 * @date :2019-04-12 10:14
 * @modified :
 */
@RestController
@RequestMapping("/api")
@Api(tags = "A会员账号")
public class ApiAccountController extends AbstractController {

    @Resource
    private ISysMemberService memberService;

    @Anonymous
    @PostMapping("open/register")
    @ApiOperation("注册")
    public ResponseEntity<ResponseBodyDto<Object>> register(@RequestBody UserRegisterRequestDto request) {
        //表单校验
        ValidatorUtil.validateEntity(request);
        BaseResponseDto response = memberService.register(request);
        return returnSuccess(response.getResCode(), response.getResMessage());
    }

    @Anonymous
    @PostMapping("open/resetPwd")
    @ApiOperation("重置密码")
    public ResponseEntity<ResponseBodyDto<Object>> resetPwd(@RequestBody UserRegisterRequestDto request) {
        //表单校验
        ValidatorUtil.validateEntity(request);
        BaseResponseDto response = memberService.resetPwd(request);
        return returnSuccess(response.getResCode(), response.getResMessage());
    }
}
